import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import { useUserStore } from './stores/user'
// import { errorHandlerPlugin } from './utils/errorHandler'
import { MobileAdaptation } from './utils/responsive'
import { pwaManager } from './utils/pwa'

// 初始化移动端适配
MobileAdaptation.init({
  themeColor: '#409EFF',
  statusBarStyle: 'default',
  disableDoubleTapZoom: true
})

// 初始化PWA功能
if ('serviceWorker' in navigator) {
  pwaManager.init().then(() => {
    console.log('PWA initialized successfully')
  }).catch(error => {
    console.error('PWA initialization failed:', error)
  })
}

const app = createApp(App)
const pinia = createPinia()

app.use(pinia)
app.use(router)
app.use(ElementPlus)
// app.use(errorHandlerPlugin) // 暂时禁用全局错误处理

// 初始化用户数据 - 在应用挂载前
const userStore = useUserStore()
userStore.initializeUser()

app.mount('#app')

